{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.collections.PathCollection at 0x2192083b400>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXoAAAD8CAYAAAB5Pm/hAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvIxREBQAAEZpJREFUeJzt3X9sXfdZx/H3hyTrPAa4o+5o3IiU0UUMIZISqvJ7dIhsFSLZtElFiBUoKkIFbRMEFibBJoHYCKzSJCgqdNDBtFK2kFVoKOtKYUKirdymTdqF0EDHaie0noa7wUxJs4c/7vF6G5zYTmzf62/eL+nqnvuc771+fHzvx+d+z7l2qgpJUru+ZtANSJJWlkEvSY0z6CWpcQa9JDXOoJekxhn0ktQ4g16SGmfQS1LjDHpJatz6QTcAcMkll9TmzZsH3YYkrSkPPfTQ56tqbKFxQxH0mzdvZmJiYtBtSNKakuTfFzPOqRtJapxBL0mNM+glqXEGvSQ1zqCXpMYNxVk3knSh2X9wir0HjnJ8ZpaNoyPs3rGFXdvGV+RrLbhHn+SlSR5M8miSx5O8p6tfkeSBJE8k+cskL+nqF3W3j3XrN69I55K0Ru0/OMWefYeZmpmlgKmZWfbsO8z+g1Mr8vUWM3XzHHBtVX0nsBV4fZJrgPcBt1TVlcB/Ajd2428E/rOqvhW4pRsnSersPXCU2ZOnXlSbPXmKvQeOrsjXWzDoq+e/upsbuksB1wIf7ep3ALu65Z3dbbr1r0uSZetYkta44zOzS6qfr0UdjE2yLskjwDPA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QS9JjTPoJalx/wdz1cQUHlB/JAAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "x = np.array([50,80,100,200])\n",
    "y = np.array([82,118,172,302])\n",
    "plt.scatter(x,y)\n",
    "# plt.grid()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "def MAE_loss(y,y_hat):\n",
    "    return np.mean(np.abs(y_hat - y))\n",
    "def MSE_loss(y, y_hat):\n",
    "    return np.mean(np.square(y_hat - y))\n",
    "\n",
    "# y_hat = np.array([-2, -1, -1, 3, 5])\n",
    "# print(MAE_loss(y, y_hat))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "def linear(x, k , b):\n",
    "    y = k * x + b\n",
    "    return y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "best k is -2.0, best b is -10.0\n",
      "best k is -2.0, best b is -9.9\n",
      "best k is -2.0, best b is -9.8\n",
      "best k is -2.0, best b is -9.700000000000001\n",
      "best k is -2.0, best b is -9.600000000000001\n",
      "best k is -2.0, best b is -9.500000000000002\n",
      "best k is -2.0, best b is -9.400000000000002\n",
      "best k is -2.0, best b is -9.300000000000002\n",
      "best k is -2.0, best b is -9.200000000000003\n",
      "best k is -2.0, best b is -9.100000000000003\n",
      "best k is -2.0, best b is -9.000000000000004\n",
      "best k is -2.0, best b is -8.900000000000004\n",
      "best k is -2.0, best b is -8.800000000000004\n",
      "best k is -2.0, best b is -8.700000000000005\n",
      "best k is -2.0, best b is -8.600000000000005\n",
      "best k is -2.0, best b is -8.500000000000005\n",
      "best k is -2.0, best b is -8.400000000000006\n",
      "best k is -2.0, best b is -8.300000000000006\n",
      "best k is -2.0, best b is -8.200000000000006\n",
      "best k is -2.0, best b is -8.100000000000007\n",
      "best k is -2.0, best b is -8.000000000000007\n",
      "best k is -2.0, best b is -7.9000000000000075\n",
      "best k is -2.0, best b is -7.800000000000008\n",
      "best k is -2.0, best b is -7.700000000000008\n",
      "best k is -2.0, best b is -7.6000000000000085\n",
      "best k is -2.0, best b is -7.500000000000009\n",
      "best k is -2.0, best b is -7.400000000000009\n",
      "best k is -2.0, best b is -7.30000000000001\n",
      "best k is -2.0, best b is -7.20000000000001\n",
      "best k is -2.0, best b is -7.10000000000001\n",
      "best k is -2.0, best b is -7.000000000000011\n",
      "best k is -2.0, best b is -6.900000000000011\n",
      "best k is -2.0, best b is -6.800000000000011\n",
      "best k is -2.0, best b is -6.700000000000012\n",
      "best k is -2.0, best b is -6.600000000000012\n",
      "best k is -2.0, best b is -6.500000000000012\n",
      "best k is -2.0, best b is -6.400000000000013\n",
      "best k is -2.0, best b is -6.300000000000013\n",
      "best k is -2.0, best b is -6.2000000000000135\n",
      "best k is -2.0, best b is -6.100000000000014\n",
      "best k is -2.0, best b is -6.000000000000014\n",
      "best k is -2.0, best b is -5.900000000000015\n",
      "best k is -2.0, best b is -5.800000000000015\n",
      "best k is -2.0, best b is -5.700000000000015\n",
      "best k is -2.0, best b is -5.600000000000016\n",
      "best k is -2.0, best b is -5.500000000000016\n",
      "best k is -2.0, best b is -5.400000000000016\n",
      "best k is -2.0, best b is -5.300000000000017\n",
      "best k is -2.0, best b is -5.200000000000017\n",
      "best k is -2.0, best b is -5.100000000000017\n",
      "best k is -2.0, best b is -5.000000000000018\n",
      "best k is -2.0, best b is -4.900000000000018\n",
      "best k is -2.0, best b is -4.8000000000000185\n",
      "best k is -2.0, best b is -4.700000000000019\n",
      "best k is -2.0, best b is -4.600000000000019\n",
      "best k is -2.0, best b is -4.5000000000000195\n",
      "best k is -2.0, best b is -4.40000000000002\n",
      "best k is -2.0, best b is -4.30000000000002\n",
      "best k is -2.0, best b is -4.200000000000021\n",
      "best k is -2.0, best b is -4.100000000000021\n",
      "best k is -2.0, best b is -4.000000000000021\n",
      "best k is -2.0, best b is -3.9000000000000217\n",
      "best k is -2.0, best b is -3.800000000000022\n",
      "best k is -2.0, best b is -3.7000000000000224\n",
      "best k is -2.0, best b is -3.6000000000000227\n",
      "best k is -2.0, best b is -3.500000000000023\n",
      "best k is -2.0, best b is -3.4000000000000234\n",
      "best k is -2.0, best b is -3.300000000000024\n",
      "best k is -2.0, best b is -3.200000000000024\n",
      "best k is -2.0, best b is -3.1000000000000245\n",
      "best k is -2.0, best b is -3.000000000000025\n",
      "best k is -2.0, best b is -2.9000000000000252\n",
      "best k is -2.0, best b is -2.8000000000000256\n",
      "best k is -2.0, best b is -2.700000000000026\n",
      "best k is -2.0, best b is -2.6000000000000263\n",
      "best k is -2.0, best b is -2.5000000000000266\n",
      "best k is -2.0, best b is -2.400000000000027\n",
      "best k is -2.0, best b is -2.3000000000000274\n",
      "best k is -2.0, best b is -2.2000000000000277\n",
      "best k is -2.0, best b is -2.100000000000028\n",
      "best k is -2.0, best b is -2.0000000000000284\n",
      "best k is -2.0, best b is -1.9000000000000288\n",
      "best k is -2.0, best b is -1.8000000000000291\n",
      "best k is -2.0, best b is -1.7000000000000295\n",
      "best k is -2.0, best b is -1.6000000000000298\n",
      "best k is -2.0, best b is -1.5000000000000302\n",
      "best k is -2.0, best b is -1.4000000000000306\n",
      "best k is -2.0, best b is -1.300000000000031\n",
      "best k is -2.0, best b is -1.2000000000000313\n",
      "best k is -2.0, best b is -1.1000000000000316\n",
      "best k is -2.0, best b is -1.000000000000032\n",
      "best k is -2.0, best b is -0.9000000000000323\n",
      "best k is -2.0, best b is -0.8000000000000327\n",
      "best k is -2.0, best b is -0.700000000000033\n",
      "best k is -2.0, best b is -0.6000000000000334\n",
      "best k is -2.0, best b is -0.5000000000000338\n",
      "best k is -2.0, best b is -0.4000000000000341\n",
      "best k is -2.0, best b is -0.30000000000003446\n",
      "best k is -2.0, best b is -0.20000000000003482\n",
      "best k is -2.0, best b is -0.10000000000003517\n",
      "best k is -2.0, best b is -3.552713678800501e-14\n",
      "best k is -2.0, best b is 0.09999999999996412\n",
      "best k is -2.0, best b is 0.19999999999996376\n",
      "best k is -2.0, best b is 0.2999999999999634\n",
      "best k is -2.0, best b is 0.39999999999996305\n",
      "best k is -2.0, best b is 0.4999999999999627\n",
      "best k is -2.0, best b is 0.5999999999999623\n",
      "best k is -2.0, best b is 0.699999999999962\n",
      "best k is -2.0, best b is 0.7999999999999616\n",
      "best k is -2.0, best b is 0.8999999999999613\n",
      "best k is -2.0, best b is 0.9999999999999609\n",
      "best k is -2.0, best b is 1.0999999999999606\n",
      "best k is -2.0, best b is 1.1999999999999602\n",
      "best k is -2.0, best b is 1.2999999999999599\n",
      "best k is -2.0, best b is 1.3999999999999595\n",
      "best k is -2.0, best b is 1.4999999999999591\n",
      "best k is -2.0, best b is 1.5999999999999588\n",
      "best k is -2.0, best b is 1.6999999999999584\n",
      "best k is -2.0, best b is 1.799999999999958\n",
      "best k is -2.0, best b is 1.8999999999999577\n",
      "best k is -2.0, best b is 1.9999999999999574\n",
      "best k is -2.0, best b is 2.099999999999957\n",
      "best k is -2.0, best b is 2.1999999999999567\n",
      "best k is -2.0, best b is 2.2999999999999563\n",
      "best k is -2.0, best b is 2.399999999999956\n",
      "best k is -2.0, best b is 2.4999999999999556\n",
      "best k is -2.0, best b is 2.5999999999999552\n",
      "best k is -2.0, best b is 2.699999999999955\n",
      "best k is -2.0, best b is 2.7999999999999545\n",
      "best k is -2.0, best b is 2.899999999999954\n",
      "best k is -2.0, best b is 2.999999999999954\n",
      "best k is -2.0, best b is 3.0999999999999535\n",
      "best k is -2.0, best b is 3.199999999999953\n",
      "best k is -2.0, best b is 3.2999999999999527\n",
      "best k is -2.0, best b is 3.3999999999999524\n",
      "best k is -2.0, best b is 3.499999999999952\n",
      "best k is -2.0, best b is 3.5999999999999517\n",
      "best k is -2.0, best b is 3.6999999999999513\n",
      "best k is -2.0, best b is 3.799999999999951\n",
      "best k is -2.0, best b is 3.8999999999999506\n",
      "best k is -2.0, best b is 3.9999999999999503\n",
      "best k is -2.0, best b is 4.09999999999995\n",
      "best k is -2.0, best b is 4.1999999999999496\n",
      "best k is -2.0, best b is 4.299999999999949\n",
      "best k is -2.0, best b is 4.399999999999949\n",
      "best k is -2.0, best b is 4.4999999999999485\n",
      "best k is -2.0, best b is 4.599999999999948\n",
      "best k is -2.0, best b is 4.699999999999948\n",
      "best k is -2.0, best b is 4.799999999999947\n",
      "best k is -2.0, best b is 4.899999999999947\n",
      "best k is -2.0, best b is 4.999999999999947\n",
      "best k is -2.0, best b is 5.099999999999946\n",
      "best k is -2.0, best b is 5.199999999999946\n",
      "best k is -2.0, best b is 5.299999999999946\n",
      "best k is -2.0, best b is 5.399999999999945\n",
      "best k is -2.0, best b is 5.499999999999945\n",
      "best k is -2.0, best b is 5.599999999999945\n",
      "best k is -2.0, best b is 5.699999999999944\n",
      "best k is -2.0, best b is 5.799999999999944\n",
      "best k is -2.0, best b is 5.8999999999999435\n",
      "best k is -2.0, best b is 5.999999999999943\n",
      "best k is -2.0, best b is 6.099999999999945\n",
      "best k is -2.0, best b is 6.1999999999999424\n",
      "best k is -2.0, best b is 6.29999999999994\n",
      "best k is -2.0, best b is 6.399999999999942\n",
      "best k is -2.0, best b is 6.499999999999943\n",
      "best k is -2.0, best b is 6.599999999999941\n",
      "best k is -2.0, best b is 6.699999999999939\n",
      "best k is -2.0, best b is 6.79999999999994\n",
      "best k is -2.0, best b is 6.899999999999942\n",
      "best k is -2.0, best b is 6.99999999999994\n",
      "best k is -2.0, best b is 7.0999999999999375\n",
      "best k is -2.0, best b is 7.199999999999939\n",
      "best k is -2.0, best b is 7.29999999999994\n",
      "best k is -2.0, best b is 7.399999999999938\n",
      "best k is -2.0, best b is 7.499999999999936\n",
      "best k is -2.0, best b is 7.5999999999999375\n",
      "best k is -2.0, best b is 7.699999999999939\n",
      "best k is -2.0, best b is 7.799999999999937\n",
      "best k is -2.0, best b is 7.899999999999935\n",
      "best k is -2.0, best b is 7.999999999999936\n",
      "best k is -2.0, best b is 8.099999999999937\n",
      "best k is -2.0, best b is 8.199999999999935\n",
      "best k is -2.0, best b is 8.299999999999933\n",
      "best k is -2.0, best b is 8.399999999999935\n",
      "best k is -2.0, best b is 8.499999999999936\n",
      "best k is -2.0, best b is 8.599999999999934\n",
      "best k is -2.0, best b is 8.699999999999932\n",
      "best k is -2.0, best b is 8.799999999999933\n",
      "best k is -1.9, best b is 7.499999999999936\n",
      "best k is -1.9, best b is 7.5999999999999375\n",
      "best k is -1.9, best b is 7.699999999999939\n",
      "best k is -1.9, best b is 7.799999999999937\n",
      "best k is -1.9, best b is 7.899999999999935\n",
      "best k is -1.9, best b is 7.999999999999936\n",
      "best k is -1.9, best b is 8.099999999999937\n",
      "best k is -1.9, best b is 8.199999999999935\n",
      "best k is -1.9, best b is 8.299999999999933\n",
      "best k is -1.9, best b is 8.399999999999935\n",
      "best k is -1.9, best b is 8.499999999999936\n",
      "best k is -1.7999999999999998, best b is 7.199999999999939\n",
      "best k is -1.7999999999999998, best b is 7.29999999999994\n",
      "best k is -1.7999999999999998, best b is 7.399999999999938\n",
      "best k is -1.7999999999999998, best b is 7.499999999999936\n",
      "best k is -1.7999999999999998, best b is 7.5999999999999375\n",
      "best k is -1.7999999999999998, best b is 7.699999999999939\n",
      "best k is -1.7999999999999998, best b is 7.799999999999937\n",
      "best k is -1.7999999999999998, best b is 7.899999999999935\n",
      "best k is -1.7999999999999998, best b is 7.999999999999936\n",
      "best k is -1.7999999999999998, best b is 8.099999999999937\n",
      "best k is -1.7999999999999998, best b is 8.199999999999935\n",
      "best k is -1.6999999999999997, best b is 6.899999999999942\n",
      "best k is -1.6999999999999997, best b is 6.99999999999994\n",
      "best k is -1.6999999999999997, best b is 7.0999999999999375\n",
      "best k is -1.6999999999999997, best b is 7.199999999999939\n",
      "best k is -1.6999999999999997, best b is 7.29999999999994\n",
      "best k is -1.6999999999999997, best b is 7.399999999999938\n",
      "best k is -1.6999999999999997, best b is 7.499999999999936\n",
      "best k is -1.6999999999999997, best b is 7.5999999999999375\n",
      "best k is -1.6999999999999997, best b is 7.699999999999939\n",
      "best k is -1.6999999999999997, best b is 7.799999999999937\n",
      "best k is -1.6999999999999997, best b is 7.899999999999935\n",
      "best k is -1.5999999999999996, best b is 6.699999999999939\n",
      "best k is -1.5999999999999996, best b is 6.79999999999994\n",
      "best k is -1.5999999999999996, best b is 6.899999999999942\n",
      "best k is -1.5999999999999996, best b is 6.99999999999994\n",
      "best k is -1.5999999999999996, best b is 7.0999999999999375\n",
      "best k is -1.5999999999999996, best b is 7.199999999999939\n",
      "best k is -1.5999999999999996, best b is 7.29999999999994\n",
      "best k is -1.5999999999999996, best b is 7.399999999999938\n",
      "best k is -1.5999999999999996, best b is 7.499999999999936\n",
      "best k is -1.5999999999999996, best b is 7.5999999999999375\n",
      "best k is -1.4999999999999996, best b is 6.399999999999942\n",
      "best k is -1.4999999999999996, best b is 6.499999999999943\n",
      "best k is -1.4999999999999996, best b is 6.599999999999941\n",
      "best k is -1.4999999999999996, best b is 6.699999999999939\n",
      "best k is -1.4999999999999996, best b is 6.79999999999994\n",
      "best k is -1.4999999999999996, best b is 6.899999999999942\n",
      "best k is -1.4999999999999996, best b is 6.99999999999994\n",
      "best k is -1.4999999999999996, best b is 7.0999999999999375\n",
      "best k is -1.4999999999999996, best b is 7.199999999999939\n",
      "best k is -1.4999999999999996, best b is 7.29999999999994\n",
      "best k is -1.3999999999999995, best b is 6.099999999999945\n",
      "best k is -1.3999999999999995, best b is 6.1999999999999424\n",
      "best k is -1.3999999999999995, best b is 6.29999999999994\n",
      "best k is -1.3999999999999995, best b is 6.399999999999942\n",
      "best k is -1.3999999999999995, best b is 6.499999999999943\n",
      "best k is -1.3999999999999995, best b is 6.599999999999941\n",
      "best k is -1.3999999999999995, best b is 6.699999999999939\n",
      "best k is -1.3999999999999995, best b is 6.79999999999994\n",
      "best k is -1.3999999999999995, best b is 6.899999999999942\n",
      "best k is -1.3999999999999995, best b is 6.99999999999994\n",
      "best k is -1.2999999999999994, best b is 5.799999999999944\n",
      "best k is -1.2999999999999994, best b is 5.8999999999999435\n",
      "best k is -1.2999999999999994, best b is 5.999999999999943\n",
      "best k is -1.2999999999999994, best b is 6.099999999999945\n",
      "best k is -1.2999999999999994, best b is 6.1999999999999424\n",
      "best k is -1.2999999999999994, best b is 6.29999999999994\n",
      "best k is -1.2999999999999994, best b is 6.399999999999942\n",
      "best k is -1.2999999999999994, best b is 6.499999999999943\n",
      "best k is -1.2999999999999994, best b is 6.599999999999941\n",
      "best k is -1.2999999999999994, best b is 6.699999999999939\n",
      "best k is -1.1999999999999993, best b is 5.499999999999945\n",
      "best k is -1.1999999999999993, best b is 5.599999999999945\n",
      "best k is -1.1999999999999993, best b is 5.699999999999944\n",
      "best k is -1.1999999999999993, best b is 5.799999999999944\n",
      "best k is -1.1999999999999993, best b is 5.8999999999999435\n",
      "best k is -1.1999999999999993, best b is 5.999999999999943\n",
      "best k is -1.1999999999999993, best b is 6.099999999999945\n",
      "best k is -1.1999999999999993, best b is 6.1999999999999424\n",
      "best k is -1.1999999999999993, best b is 6.29999999999994\n",
      "best k is -1.1999999999999993, best b is 6.399999999999942\n",
      "best k is -1.0999999999999992, best b is 5.299999999999946\n",
      "best k is -1.0999999999999992, best b is 5.399999999999945\n",
      "best k is -1.0999999999999992, best b is 5.499999999999945\n",
      "best k is -1.0999999999999992, best b is 5.599999999999945\n",
      "best k is -1.0999999999999992, best b is 5.699999999999944\n",
      "best k is -1.0999999999999992, best b is 5.799999999999944\n",
      "best k is -1.0999999999999992, best b is 5.8999999999999435\n",
      "best k is -1.0999999999999992, best b is 5.999999999999943\n",
      "best k is -1.0999999999999992, best b is 6.099999999999945\n",
      "best k is -0.9999999999999991, best b is 4.999999999999947\n",
      "best k is -0.9999999999999991, best b is 5.099999999999946\n",
      "best k is -0.9999999999999991, best b is 5.199999999999946\n",
      "best k is -0.9999999999999991, best b is 5.299999999999946\n",
      "best k is -0.9999999999999991, best b is 5.399999999999945\n",
      "best k is -0.9999999999999991, best b is 5.499999999999945\n",
      "best k is -0.9999999999999991, best b is 5.599999999999945\n",
      "best k is -0.9999999999999991, best b is 5.699999999999944\n",
      "best k is -0.9999999999999991, best b is 5.799999999999944\n",
      "best k is -0.899999999999999, best b is 4.699999999999948\n",
      "best k is -0.899999999999999, best b is 4.799999999999947\n",
      "best k is -0.899999999999999, best b is 4.899999999999947\n",
      "best k is -0.899999999999999, best b is 4.999999999999947\n",
      "best k is -0.899999999999999, best b is 5.099999999999946\n",
      "best k is -0.899999999999999, best b is 5.199999999999946\n",
      "best k is -0.899999999999999, best b is 5.299999999999946\n",
      "best k is -0.899999999999999, best b is 5.399999999999945\n",
      "best k is -0.899999999999999, best b is 5.499999999999945\n",
      "best k is -0.7999999999999989, best b is 4.399999999999949\n",
      "best k is -0.7999999999999989, best b is 4.4999999999999485\n",
      "best k is -0.7999999999999989, best b is 4.599999999999948\n",
      "best k is -0.7999999999999989, best b is 4.699999999999948\n",
      "best k is -0.7999999999999989, best b is 4.799999999999947\n",
      "best k is -0.7999999999999989, best b is 4.899999999999947\n",
      "best k is -0.7999999999999989, best b is 4.999999999999947\n",
      "best k is -0.7999999999999989, best b is 5.099999999999946\n",
      "best k is -0.7999999999999989, best b is 5.199999999999946\n",
      "best k is -0.6999999999999988, best b is 4.1999999999999496\n",
      "best k is -0.6999999999999988, best b is 4.299999999999949\n",
      "best k is -0.6999999999999988, best b is 4.399999999999949\n",
      "best k is -0.6999999999999988, best b is 4.4999999999999485\n",
      "best k is -0.6999999999999988, best b is 4.599999999999948\n",
      "best k is -0.6999999999999988, best b is 4.699999999999948\n",
      "best k is -0.6999999999999988, best b is 4.799999999999947\n",
      "best k is -0.6999999999999988, best b is 4.899999999999947\n",
      "best k is -0.5999999999999988, best b is 3.8999999999999506\n",
      "best k is -0.5999999999999988, best b is 3.9999999999999503\n",
      "best k is -0.5999999999999988, best b is 4.09999999999995\n",
      "best k is -0.5999999999999988, best b is 4.1999999999999496\n",
      "best k is -0.5999999999999988, best b is 4.299999999999949\n",
      "best k is -0.5999999999999988, best b is 4.399999999999949\n",
      "best k is -0.5999999999999988, best b is 4.4999999999999485\n",
      "best k is -0.5999999999999988, best b is 4.599999999999948\n",
      "best k is -0.49999999999999867, best b is 3.5999999999999517\n",
      "best k is -0.49999999999999867, best b is 3.6999999999999513\n",
      "best k is -0.49999999999999867, best b is 3.799999999999951\n",
      "best k is -0.49999999999999867, best b is 3.8999999999999506\n",
      "best k is -0.49999999999999867, best b is 3.9999999999999503\n",
      "best k is -0.49999999999999867, best b is 4.09999999999995\n",
      "best k is -0.49999999999999867, best b is 4.1999999999999496\n",
      "best k is -0.49999999999999867, best b is 4.299999999999949\n",
      "best k is -0.3999999999999986, best b is 3.2999999999999527\n",
      "best k is -0.3999999999999986, best b is 3.3999999999999524\n",
      "best k is -0.3999999999999986, best b is 3.499999999999952\n",
      "best k is -0.3999999999999986, best b is 3.5999999999999517\n",
      "best k is -0.3999999999999986, best b is 3.6999999999999513\n",
      "best k is -0.3999999999999986, best b is 3.799999999999951\n",
      "best k is -0.3999999999999986, best b is 3.8999999999999506\n",
      "best k is -0.3999999999999986, best b is 3.9999999999999503\n",
      "best k is -0.2999999999999985, best b is 3.0999999999999535\n",
      "best k is -0.2999999999999985, best b is 3.199999999999953\n",
      "best k is -0.2999999999999985, best b is 3.2999999999999527\n",
      "best k is -0.2999999999999985, best b is 3.3999999999999524\n",
      "best k is -0.2999999999999985, best b is 3.499999999999952\n",
      "best k is -0.2999999999999985, best b is 3.5999999999999517\n",
      "best k is -0.2999999999999985, best b is 3.6999999999999513\n",
      "best k is -0.1999999999999984, best b is 2.7999999999999545\n",
      "best k is -0.1999999999999984, best b is 2.899999999999954\n",
      "best k is -0.1999999999999984, best b is 2.999999999999954\n",
      "best k is -0.1999999999999984, best b is 3.0999999999999535\n",
      "best k is -0.1999999999999984, best b is 3.199999999999953\n",
      "best k is -0.1999999999999984, best b is 3.2999999999999527\n",
      "best k is -0.1999999999999984, best b is 3.3999999999999524\n",
      "best k is -0.09999999999999831, best b is 2.4999999999999556\n",
      "best k is -0.09999999999999831, best b is 2.5999999999999552\n",
      "best k is -0.09999999999999831, best b is 2.699999999999955\n",
      "best k is -0.09999999999999831, best b is 2.7999999999999545\n",
      "best k is -0.09999999999999831, best b is 2.899999999999954\n",
      "best k is -0.09999999999999831, best b is 2.999999999999954\n",
      "best k is -0.09999999999999831, best b is 3.0999999999999535\n",
      "best k is 1.7763568394002505e-15, best b is 2.2999999999999563\n",
      "best k is 1.7763568394002505e-15, best b is 2.399999999999956\n",
      "best k is 1.7763568394002505e-15, best b is 2.4999999999999556\n",
      "best k is 1.7763568394002505e-15, best b is 2.5999999999999552\n",
      "best k is 1.7763568394002505e-15, best b is 2.699999999999955\n",
      "best k is 1.7763568394002505e-15, best b is 2.7999999999999545\n",
      "best k is 0.10000000000000187, best b is 1.9999999999999574\n",
      "best k is 0.10000000000000187, best b is 2.099999999999957\n",
      "best k is 0.10000000000000187, best b is 2.1999999999999567\n",
      "best k is 0.10000000000000187, best b is 2.2999999999999563\n",
      "best k is 0.10000000000000187, best b is 2.399999999999956\n",
      "best k is 0.10000000000000187, best b is 2.4999999999999556\n",
      "best k is 0.20000000000000195, best b is 1.6999999999999584\n",
      "best k is 0.20000000000000195, best b is 1.799999999999958\n",
      "best k is 0.20000000000000195, best b is 1.8999999999999577\n",
      "best k is 0.20000000000000195, best b is 1.9999999999999574\n",
      "best k is 0.20000000000000195, best b is 2.099999999999957\n",
      "best k is 0.20000000000000195, best b is 2.1999999999999567\n",
      "best k is 0.30000000000000204, best b is 1.4999999999999591\n",
      "best k is 0.30000000000000204, best b is 1.5999999999999588\n",
      "best k is 0.30000000000000204, best b is 1.6999999999999584\n",
      "best k is 0.30000000000000204, best b is 1.799999999999958\n",
      "best k is 0.30000000000000204, best b is 1.8999999999999577\n",
      "best k is 0.40000000000000213, best b is 1.1999999999999602\n",
      "best k is 0.40000000000000213, best b is 1.2999999999999599\n",
      "best k is 0.40000000000000213, best b is 1.3999999999999595\n",
      "best k is 0.40000000000000213, best b is 1.4999999999999591\n",
      "best k is 0.40000000000000213, best b is 1.5999999999999588\n",
      "best k is 0.5000000000000022, best b is 0.9999999999999609\n",
      "best k is 0.5000000000000022, best b is 1.0999999999999606\n",
      "best k is 0.5000000000000022, best b is 1.1999999999999602\n",
      "best k is 0.5000000000000022, best b is 1.2999999999999599\n",
      "best k is 0.6000000000000023, best b is 0.699999999999962\n",
      "best k is 0.6000000000000023, best b is 0.7999999999999616\n",
      "best k is 0.6000000000000023, best b is 0.8999999999999613\n",
      "best k is 0.6000000000000023, best b is 0.9999999999999609\n",
      "best k is 0.7000000000000024, best b is 0.4999999999999627\n",
      "best k is 0.7000000000000024, best b is 0.5999999999999623\n",
      "best k is 0.7000000000000024, best b is 0.699999999999962\n",
      "best k is 0.8000000000000025, best b is 0.2999999999999634\n",
      "best k is 0.8000000000000025, best b is 0.39999999999996305\n"
     ]
    }
   ],
   "source": [
    "# inf代表正无穷\n",
    "min_loss = float('inf')\n",
    "for k in np.arange(-2, 2, 0.1):\n",
    "    for b in np.arange(-10, 10, 0.1):\n",
    "        y_hat = [linear(xi, k, b) for xi in list(x)]\n",
    "        current_loss = MSE_loss(y, y_hat)\n",
    "#         print('current_loss is {}'.format(current_loss))\n",
    "        if current_loss < min_loss:\n",
    "            min_loss = current_loss\n",
    "            best_k , best_b = k, b\n",
    "            print('best k is {}, best b is {}'.format(best_k, best_b))\n",
    "# print(current_loss)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD8CAYAAACMwORRAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4zLCBodHRwOi8vbWF0cGxvdGxpY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MLP2mfhuMysgFNG/uPv4JoZkfJs1lynK7RX7zhVAJXBko1Xrt5WZbQ5sRwYPx20sl7svc/dVsad/BkozEKcX0M/MPgEqgN5m9mijMVFsr2ZzRbS9cPdFsf/9FHgKOKDRkLT+LuZ6cc/Y5NyJMLPtvznWaGYHELbzsgx8rwH3A7Pd/ZaNDMvoNosnUxTby8w6mFnb2HIhcBjwfqNhE4HBseUBwCSPnQmLMlej47L9COcx0srdh7l7J3fvTDhZOsndBzUalvHtFU+uKLaXmW1tZtt8swwcATS+ui6tv4vNzqEaJcuyybkTyDUAONvM6oE6YGC6f8hjegG/BKpix2wB/gD8sEG2TG+zeDJFsb06Ag+ZWRvCH5Mn3P0ZMxsBTHX3iYQ/So+Y2VzCHujANGeKN9f5ZtYPqI/lOi0DuZqUBdsrnlxRbK9i4KnYPsvmwGPu/ryZnQWZ+V3UHaoiInko1w/LiIhIE1TcRUTykIq7iEgeUnEXEclDKu4iInlIxV1EJA+puIuI5CEVdxGRPPT/AZnOE4ZzdrG9AAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "y_hat = best_k * x + best_b\n",
    "plt.scatter(x, y)\n",
    "plt.plot(x, y_hat, 'red')\n",
    "plt.grid()\n",
    "plt.show()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
